package cn.edu.xjtu.data_structure.experiment.ex_1;

import java.io.FileReader;
import java.io.IOException;
import java.io.StreamTokenizer;

/**
 * @author yjq
 * @version 1.0
 * @date 2021/10/22 19:58
 */
public class MyListTest {
    private static final int INSERT = '+';//插入
    private static final int REMOVE = '-';//删除
    private static final int REPLACE = '=';//替换
    private static final int BEGIN = '#';//回到开头
    private static final int END = '*';//回到结尾
    private static final int NEXT = '>';//下一个
    private static final int PREV = '<';//上一个
    private static final int CLEAR = '~';//清空


    public static void main(String[] args) throws IOException {
        //测试线性表
        MyList<Character> test = new MyList<>(1000);
        StreamTokenizer stk = new StreamTokenizer(new FileReader("src/testCase.txt"));
        stk.eolIsSignificant(true);//不忽略换行
        int nextToken = stk.nextToken();
        while (nextToken != StreamTokenizer.TT_EOF) {// 文件结束退出循环
            switch (stk.ttype) {
                case (INSERT):// 判断是否是'+'
                    nextToken = stk.nextToken();
                    if (stk.ttype == StreamTokenizer.TT_WORD) {
                        char element = stk.sval.charAt(0);
                        test.insert(element);
                    }
                    break;
                case (REPLACE):// 判断是否是'='
                    if (!test.isEmpty()) {
                        nextToken = stk.nextToken();
                        if (stk.ttype == StreamTokenizer.TT_WORD) {
                            char element = stk.sval.charAt(0);
                            test.replace(element);
                        }
                    }
                    break;
                case (REMOVE)://判断是否为'-'
                    if (!test.isEmpty()) {
                        test.remove();
                    }
                    break;
                case (BEGIN)://判断是否为'#'
                    test.gotoBeginning();
                    break;
                case (END)://判断是否为'*'
                    test.gotoEnd();
                    break;
                case (NEXT)://判断是否为'>'
                    if (!test.isEmpty())
                        test.gotoNext();
                    break;
                case (PREV)://判断是否为'<'
                    if (!test.isEmpty())
                        test.gotoPrev();
                    break;
                case (CLEAR)://判断是否为'~'
                    test.clear();
                    break;
                case (StreamTokenizer.TT_EOL)://判断是否为'~'
                    test.showStructure();
                    break;
            }
            nextToken = stk.nextToken();
        }
        test.bw.close();
    }

}
